GBML manual / Queues

queue_push

Pushes value onto the back of target, a queue - first in, first out. Returns true if it fit, false if target was already full (nothing is pushed - target never crashes or corrupts, it just stops growing).

Syntax

queue_push(target, value) -> bool

Arguments

NameType
targetqueue
valueelement

Returns

bool

Description

Pushes value onto the back of target, a queue<T> - first in, first out. Returns true if it fit, false if target was already full (nothing is pushed - target never crashes or corrupts, it just stops growing).

target is a real fixed-size double-ended queue that holds up to N items - N is target's own declared capacity (/// @capacity, default 8 if untagged). If the return value is ignored, target simply stops accepting new items until something is popped; check it only when the game needs to react to "no room left."

A queue<T>'s own capacity must always be a power of two (2, 4, 8, 16, 32, ...) - its underlying storage (a double-ended queue) requires it. /// @capacity 10 is refused at check time, naming the nearest legal size to use instead (16); the untagged default (8) already satisfies this, so an untagged queue<T> is never affected.

queue<T> has no [i] indexing - unlike array<T>/list<T>/grid<T>, the front is the only item you can ever reach directly. Declare the variable list<T> instead if you need to look inside it by index or search it.

Example

/// @type {queue<int>}
/// @capacity 4
var turn_order = [];
queue_push(turn_order, 1);
var added = queue_push(turn_order, 2); // true - there was room
A real capture - the queue right after queue_push(turn_order, 1)A real capture - the queue right after queue_push(turn_order, 1)
A real capture - the queue right after queuepush(turnorder, 1)
The same queue after queue_push(turn_order, 2) too - both items now show, in orderThe same queue after queue_push(turn_order, 2) too - both items now show, in order
The same queue after queuepush(turnorder, 2) too - both items now show, in order

On the GBA

target is a real fixed-size double-ended queue of T items, up to N - N is target's own declared capacity (`/// @capacity`, default 8 if untagged, and always a POWER OF TWO - any other tagged value is refused at check time, see this file's own Queues header). Checks target.full() before ever calling push_back, the identical safety check stack_push/list_add already make. O(1).

See also: queue_popqueue_peekqueue_lengthqueue_clearqueue_emptyData containers